package 动态规划.爬楼梯;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/3/14 16:31
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        System.out.println(climbStairs(3));
    }

    //超出时间限制
    public static int climbStairs(int n) {
        if (n == 1 || n == 2){
            return n;
        }
        return climbStairs(n-1) + climbStairs(n - 2);
    }

    //推荐解法
    public static int climbStairs2(int n) {
        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 1;
        for(int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
            if (dp[i] > 1000000007){
                dp[i] = dp[i]%1000000007;
            }
        }
        return dp[n];
    }



}
